/**************************************************************
 *@ProjectName: blweibo
 *@FileName: BaseLayout.java
 *@Date: 2011-5-31
 *@Copyright: 2011 www.hrbanlv.com Inc. All rights reserved.
 **************************************************************/
package com.zhiweibo;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

/**
 * The Class BaseLayout.
 * 
 * @author SunHaibin
 * @since Android 1.6
 * @history 2011-5-31
 */
public class BaseLayout extends RelativeLayout {

    /** The left button. */
    public Button leftButton;

    /** The ly button group. */
    public LinearLayout lyButtonGroup;

    /** The m button1. */
    public Button mButton1;

    /** The m button2. */
    public Button mButton2;

    /** The m button3. */
    public Button mButton3;

    /** The progress button. */
    public RelativeLayout progressButton;

    /** The right button. */
    public Button rightButton;

    /** The tv info. */
    public TextView tvInfo;

    /**
     * Instantiates a new base layout.
     * 
     * @param paramContext
     *            the param context
     * @param paramInt
     *            the param int
     */
    public BaseLayout(Context paramContext, int paramInt) {
        super(paramContext);
        LayoutInflater localLayoutInflater = (LayoutInflater) paramContext.getSystemService("layout_inflater");
        View localView1 = localLayoutInflater.inflate(R.layout.titlebar, null);
        Object localObject = new RelativeLayout.LayoutParams(-1, 45);
        switch (WeiboApplication.getTitleDisplayMode()) {
        case 0:
            localObject = new RelativeLayout.LayoutParams(-1, 69);
            break;
        case 1:
            localObject = new RelativeLayout.LayoutParams(-1, 45);
            break;
        case 2:
            localObject = new RelativeLayout.LayoutParams(-1, 35);
            break;
        }
        ((RelativeLayout.LayoutParams) localObject).addRule(10);
        addView(localView1, (ViewGroup.LayoutParams) localObject);
        RelativeLayout.LayoutParams localLayoutParams = new RelativeLayout.LayoutParams(-1, -1);
        localLayoutParams.addRule(3, R.id.lyTitleBar);
        addView(localLayoutInflater.inflate(paramInt, null), localLayoutParams);
        leftButton = (Button) localView1.findViewById(R.id.titleBack);
        rightButton = (Button) localView1.findViewById(R.id.titleSave);
        tvInfo = (TextView) localView1.findViewById(R.id.titleText);
        lyButtonGroup = (LinearLayout) localView1.findViewById(R.id.titleembededButtons);
        mButton1 = (Button) localView1.findViewById(R.id.titleat);
        mButton2 = (Button) localView1.findViewById(R.id.titlecomment);
        mButton3 = (Button) localView1.findViewById(R.id.titlemessage);
        progressButton = (RelativeLayout) localView1.findViewById(R.id.rlProgressBar);
    }

    /**
     * Sets the button type and info.
     * 
     * @param paramInt
     *            the param int
     * @param paramString1
     *            the param string1
     * @param paramString2
     *            the param string2
     * @param paramString3
     *            the param string3
     */
    public void setButtonTypeAndInfo(int paramInt, String paramString1, String paramString2, String paramString3) {
        lyButtonGroup.setVisibility(View.GONE);
        switch (paramInt) {
        case 1:
            if (TextUtils.isEmpty(paramString1)) {
                leftButton.setVisibility(View.GONE);
            } else {
                String s3 = getResources().getString(R.string.main_edit);
                if (paramString1.equalsIgnoreCase(s3)) {
                    leftButton.setBackgroundDrawable(getResources().getDrawable(R.drawable.title_new));
                } else {
                    leftButton.setText(paramString1);
                    leftButton.setBackgroundDrawable(getResources().getDrawable(R.drawable.title_button));
                }
            }
            if (!TextUtils.isEmpty(paramString2)) {
                setTitle(paramString2);
            }
            if (TextUtils.isEmpty(paramString3)) {
                rightButton.setVisibility(View.GONE);
            } else if (paramString3.equalsIgnoreCase(getResources().getString(R.string.main_home))) {
                rightButton.setBackgroundDrawable(getResources().getDrawable(R.drawable.title_home));
            } else if (paramString3.equalsIgnoreCase(getResources().getString(R.string.main_reload))) {
                rightButton.setBackgroundDrawable(getResources().getDrawable(R.drawable.title_reload));
            } else if (paramString3.equalsIgnoreCase(getResources().getString(R.string.account_regist_titlebtn))) {
                rightButton.setBackgroundDrawable(getResources().getDrawable(R.drawable.title_regist));
            } else {
                rightButton.setText(paramString3);
                rightButton.setBackgroundDrawable(getResources().getDrawable(R.drawable.title_button));
            }
            break;
        case 0:
            leftButton.setVisibility(View.GONE);
            rightButton.setVisibility(View.GONE);
            tvInfo.setVisibility(View.GONE);
            lyButtonGroup.setVisibility(0);
            break;
        }
    }

    /**
     * Sets the title.
     * 
     * @param paramString
     *            the new title
     */
    public void setTitle(String paramString) {
        tvInfo.setText(paramString);
    }

}
